import { configToSearch, toSearchHandle } from '@/views/datacenter/business/utils/index'
const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '组织单位', prop: 'unitName' },
		{ label: '培训单位名称', prop: 'trainingUnitName' },
		{
			label: '培训类型',
			prop: 'trainingType',
			propName: 'trainingTypeLabel',
			type: 'remoteSelect',
			code: 'TRAINING_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 6,
		},
		{ label: '培训天数', prop: 'trainingDays' },
		{ label: '培训对象', prop: 'trainingObject' },
		{
			label: '培训日期',
			prop: 'trainingDate',
		},
		{ label: '培训内容', prop: 'trainingContent' },
		{
			label: '是否可信',
			prop: 'isBelievable',
			custome: 'tag',
			dicData: [
				{ label: '否', value: 0, type: 'danger' },
				{ label: '是', value: 1, type: 'success' },
			],
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

// 详情
export const detailConfig = {
	inline: false,
	showBtn: false,
	labelPosition: 'left',
	column: [
		{
			label: '组织单位',
			prop: 'unitName',
			span: 8,
			maxlength: '50',
			showWordLimit: true,
			type: 'text',
		},
		{
			label: '培训单位名称',
			prop: 'trainingUnitName',
			span: 8,
			maxlength: '50',
			showWordLimit: true,
			type: 'text',
		},
		{
			label: '培训类型',
			prop: 'trainingType',
			propName: 'trainingTypeLabel',
			type: 'remoteSelect',
			code: 'TRAINING_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '培训地点',
			prop: 'trainingPlace',
			span: 8,
			maxlength: '140',
			showWordLimit: true,
			type: 'text',
		},
		{
			label: '培训日期',
			prop: 'trainingDate',
			span: 8,
			type: 'date',
			changeField: true,
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
		},
		{
			label: '培训天数',
			prop: 'trainingDays',
			type: 'input',
			span: 8,
		},
		{
			label: '培训对象',
			prop: 'trainingObject',
			span: 8,
			maxlength: '50',
			showWordLimit: true,
			type: 'text',
		},
		{
			label: '身份证号',
			prop: 'idCard',
			span: 8,
			type: 'text',
		},
		{
			label: '培训人数',
			prop: 'trainingNum',
			type: 'input',
			span: 8,
		},
		{
			label: '培训成果',
			prop: 'trainingResult',
			maxlength: '140',
			showWordLimit: true,
			changeField: true,
			type: 'text',
			span: 24,
		},
		{
			label: '培训内容',
			prop: 'trainingContent',
			maxlength: '500',
			showWordLimit: true,
			changeField: true,
			type: 'textarea',
			span: 24,
		},
		{
			label: '培训现场照片',
			prop: 'trainingPhoto',
			type: 'upload',
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			limit: 9,
			multiple: true,
			custome: 'img',
			span: 24,
		},
	],
}

export const formConfig = {
	...detailConfig,
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '150px',
}
const moreSearchConfig: any = {
	inline: true,
	showBtn: false,
	labelPosition: 'left',
	column: [...configToSearch(formConfig.column)],
}

export const api = {
	index: 'view_dpTrainingRecord_page',
	add: 'view_dpTrainingRecord_gather',
	edit: 'view_dpTrainingRecord_edit',
	import: 'view_dpTrainingRecord_import',
	export: 'view_dpTrainingRecord_export',
	delete: 'view_dpTrainingRecord_del',
	detail: 'view_dpTrainingRecord_view',
}
export const baseConfig = {
	pageName: '从业人员培训记录',
	dictcodes: ['TRAINING_TYPE'],
	addLabel: '新增',
	rowKey: 'id',
	tipLabel: 'name',
	exportMqTopic: '/ning/export/',
	api,
	auth: {
		...api,
		mulitSet: 'mulitSet',
	},
	menuBtn: [
		{
			icon: 'detail',
			label: '查看详情',
			type: 'primary',
			operate: 'detail',
			auth: api.detail,
			text: true,
			show: true,
		},
		{
			icon: 'editor',
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: api.edit,
			text: true,
			show: true,
		},
	],
	paramsObj: {
		code: 2010,
	},
	dialogConfig: {
		width: '80%',
	},
	moreSearchConfig,
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'right',
		labelWidth: 80,
		column: [
			{ label: '组织单位', prop: 'unitName', type: 'input', span: 8 },
			{ label: '培训对象', prop: 'trainingObject', type: 'input', span: 8 },
			{ label: '培训单位', prop: 'trainingUnitName', type: 'input', span: 8 },
			{
				label: '培训类型',
				prop: 'trainingType',
				propName: 'trainingTypeLabel',
				type: 'remoteSelect',
				code: 'TRAINING_TYPE',
				api: 'getDictItemList',
				filterKey: 'value',
				multiple: false,
				span: 8,
			},
			{ label: '培训天数', prop: 'trainingDays', type: 'number', span: 8 },
			{
				label: '培训日期',
				prop: 'trainingDate',
				span: 8,
				type: 'date',
				changeField: true,
				format: 'YYYY年MM月DD日',
				valueFormat: 'YYYY-MM-DD',
			},
		],
	},
	tableConfig,
	detailConfig,
	formConfig,
	beforeOnLoadFormate: async (params) => {
		params = toSearchHandle(moreSearchConfig, {}, params)
		return Promise.resolve({
			...params,
		})
	},
}
